﻿<Window x:Class="OptionWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
    xmlns:Commands="clr-namespace:iConverter.Commands" 
    Title="选项" Height="480" Width="640" Icon="Images\Settings_32x32.png" 
    ShowInTaskbar="False"     ResizeMode="CanResizeWithGrip" WindowStartupLocation="CenterOwner" Name="OptionWindow">

    <Window.Resources>
        <LinearGradientBrush x:Key="SeparatorBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#00D2D3D4" Offset="1" />
            <GradientStop Color="#7FD2D3D4" />
            <GradientStop Color="#FFD2D3D4" Offset="0.246" />
            <GradientStop Color="#FFD2D3D4" Offset="0.797" />
        </LinearGradientBrush>
        <Style x:Key="OptionLabelStyle" TargetType="{x:Type Label}">
            <Setter Property="Control.FontSize" Value="14" />
            <Setter Property="Control.FontWeight" Value="Bold" />
            <Setter Property="Control.Background" Value="AliceBlue" />
        </Style>
        <DataTemplate x:Key="EncodingItemTemplate">
            <DataTemplate.Resources>
                <Storyboard x:Key="MouseEnterStoryboard">
                    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="border">
                        <EasingColorKeyFrame KeyTime="0" Value="Transparent"/>
                        <EasingColorKeyFrame KeyTime="0:0:1" Value="#FF00A7FF"/>
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="MouseLeaveStoryboard">
                    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="border">
                        <SplineColorKeyFrame KeyTime="0" Value="#FF00A7FF"/>
                        <SplineColorKeyFrame KeyTime="0:0:1" Value="Transparent"/>
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </DataTemplate.Resources>
            <Border x:Name="border" Margin="1" CornerRadius="3" BorderThickness="1" BorderBrush="Transparent" >
                <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" IsEnabled="{Binding CanCheck}" x:Name="chkbox" >
                    <StackPanel DataContext="{Binding Item}" Orientation="Horizontal" x:Name="stackPanel">
                        <TextBlock Text="{Binding EncodingName}" />
                        <TextBlock Margin="15,0,0,0"><Run Text="("/></TextBlock>
                        <TextBlock Text="{Binding WebName, StringFormat=Name: \{0\}}" />
                        <TextBlock Margin="10,0,0,0" Text="{Binding CodePage, StringFormat=CodePage: \{0\}}" />
                        <TextBlock><Run Text=")"/></TextBlock>
                    </StackPanel>
                </CheckBox>
            </Border>
            <DataTemplate.Triggers>
                <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="border">
                    <BeginStoryboard x:Name="MouseLeaveStoryboard_BeginStoryboard" Storyboard="{StaticResource MouseLeaveStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="border">
                    <BeginStoryboard Storyboard="{StaticResource MouseEnterStoryboard}"/>
                </EventTrigger>
                <Trigger Property="IsChecked" SourceName="chkbox" Value="False">
                    <!--<Setter Property="Background" TargetName="stackPanel" Value="LightGray" />-->
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsEnabled" SourceName="chkbox" Value="False" />
                        <Condition Property="IsChecked" SourceName="chkbox" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Foreground" TargetName="chkbox" Value="Red" />
                </MultiTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <DataTemplate x:Key="PluginProviderTemplate">
            <DataTemplate.Resources>
                <Storyboard x:Key="MouseEnterStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="recBackground" Storyboard.TargetProperty="(UIElement.Opacity)">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0" />
                        <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1" />
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="MouseLeaveStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="recBackground" Storyboard.TargetProperty="(UIElement.Opacity)">
                        <EasingDoubleKeyFrame KeyTime="0" Value="1" />
                        <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </DataTemplate.Resources>

            <Border Background="Transparent" BorderBrush="AliceBlue" BorderThickness="1" Margin="1" Name="border" >
                <Grid TextBlock.Foreground="Black">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Rectangle Grid.ColumnSpan="5" Grid.RowSpan="5" Opacity="0" Name="recBackground">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="White" Offset="0" />
                                <GradientStop Color="#FFFFF0D0" Offset="0.5" />
                                <GradientStop Color="#FFFCEBBA" Offset="0.5" />
                                <GradientStop Color="#FFFFEBB6" Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Image Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="3" Height="32" HorizontalAlignment="Left" Margin="3" Source="{Binding Path=Icon, Mode=OneWay}" Stretch="Uniform" VerticalAlignment="Stretch" Width="32" Name="imgIcon" />
                    <TextBlock FontWeight="Bold" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="1" Text="{Binding Path=Name, Mode=OneWay}" VerticalAlignment="Center" Name="txtName" />
                    <TextBlock Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="1" Text="{Binding Mode=OneWay, Path=Version, StringFormat=版本： \{0\}}" VerticalAlignment="Center" Name="txtVersion" />
                    <TextBlock Grid.Column="2" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="1" Text="{Binding Mode=OneWay, Path=Author, StringFormat=作者： \{0\}}" VerticalAlignment="Center" Name="txtAuthor" />
                    <TextBlock Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" Grid.RowSpan="1" Text="{Binding Mode=OneWay, Path=Description}" TextTrimming="WordEllipsis" TextWrapping="NoWrap" Name="txtDescription"  />
                    <Button Command="Commands:OptionCommands.PluginEnableCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Content="开启" Grid.Column="4" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="1" Height="22" Margin="3" VerticalAlignment="Top" Width="70" Name="btnEnable" />
                    <Button Command="Commands:OptionCommands.PluginDisableCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Content="禁用" Grid.Column="4" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="1" Height="22" Margin="3" VerticalAlignment="Top" Width="70" Name="btnDisable" />
                    <Button Command="Commands:OptionCommands.PluginConfigCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Content="配置" Grid.Column="4" Grid.ColumnSpan="1" Grid.Row="2" Grid.RowSpan="1" Height="22" Margin="3" VerticalAlignment="Top" Visibility="Hidden" Width="70" Name="btnConfig" />
                </Grid>
            </Border>

            <DataTemplate.Triggers>
                <Trigger Property="UIElement.IsEnabled" SourceName="btnDisable" Value="False">
                    <Setter Property="Border.Background" TargetName="border" Value="LightGray" />
                    <Setter Property="UIElement.IsEnabled" TargetName="btnEnable" Value="True" />
                </Trigger>
                <Trigger Property="UIElement.IsEnabled" SourceName="btnConfig" Value="True">
                    <Setter Property="UIElement.Visibility" TargetName="btnConfig" Value="Visible" />
                </Trigger>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
                    <Setter Property="Border.Background" TargetName="border" Value="#FFFFE5A8" />
                    <Setter Property="TextBlock.TextTrimming" TargetName="txtDescription" Value="WordEllipsis"  />
                    <Setter Property="TextBlock.TextWrapping" TargetName="txtDescription" Value="Wrap" />
                </DataTrigger>
                <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="border">
                    <BeginStoryboard Storyboard="{StaticResource MouseEnterStoryboard}" Name="MouseEnterStoryboard_BeginStoryboard" />
                </EventTrigger>
                <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="border">
                    <BeginStoryboard Storyboard="{StaticResource MouseLeaveStoryboard}" Name="MouseLeaveStoryboard_BeginStoryboard" />
                </EventTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <DataTemplate x:Key="UsePostProcessingItemTemplate">
            <DataTemplate.Resources>
                <Storyboard x:Key="MouseEnterStoryboard">
                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
                        <EasingColorKeyFrame KeyTime="0" Value="AliceBlue" />
                        <EasingColorKeyFrame KeyTime="0:0:1" Value="#FF00A7FF" />
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="MouseLeaveStoryboard">
                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
                        <SplineColorKeyFrame KeyTime="0" Value="AliceBlue" />
                        <SplineColorKeyFrame KeyTime="0:0:1" Value="Transparent" />
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </DataTemplate.Resources>
            <Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="3" Margin="1" Name="border">
                <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" IsEnabled="{Binding CanCheck}" Name="chkbox">
                    <Grid DataContext="{Binding Item}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock FontWeight="Bold" Grid.Row="0" Text="{Binding Name}" VerticalAlignment="Center" />
                        <StackPanel Grid.Column="2" Grid.ColumnSpan="1" Grid.Row="0" Orientation="Horizontal">
                            <Button Command="Commands:OptionCommands.MovePostProcessingTopCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Height="24" Margin="10,3,10,3" Width="24">
                                <Path Data="M 7.37183,16.5L 7.37183,7.66306L 11.1667,11.1242L 11.1667,8.61618L 5.83337,3.75183L 0.500061,8.61618L 0.500061,11.1242L 4.29492,7.66306L 4.29492,16.5L 7.37183,16.5 Z M 0.5,0.5L 11.1666,0.5L 11.1666,2.66031L 0.5,2.66031L 0.5,0.5 Z " Fill="#FF000000" StrokeLineJoin="Round" />
                            </Button>
                            <Button Command="Commands:OptionCommands.MovePostProcessingUpCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Height="24" Margin="10,3,10,3" Width="24">
                                <Path Data="M 7.3717,16L 7.3717,7.16309L 11.1666,10.6243L 11.1666,8.11621L 5.83331,3.25186L 0.5,8.11621L 0.5,10.6242L 4.2948,7.16309L 4.2948,16L 7.3717,16 Z " Fill="#FF000000" StrokeLineJoin="Round" />
                            </Button>
                            <Button Command="Commands:OptionCommands.MovePostProcessingDownCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Height="24" Margin="10,3,10,3" Width="24">
                                <Path Data="M 4.29492,0.5L 4.29492,9.33694L 0.5,5.87573L 0.5,8.38379L 5.83331,13.2482L 11.1666,8.38379L 11.1666,5.87576L 7.37183,9.33691L 7.37183,0.5L 4.29492,0.5 Z " Fill="#FF000000" StrokeLineJoin="Round" />
                            </Button>
                            <Button Command="Commands:OptionCommands.MovePostProcessingBottomCommand" CommandParameter="{Binding}" CommandTarget="{Binding ElementName=OptionWindow}" Height="24" Margin="10,3,10,3" Width="24">
                                <Path Data="M 4.29492,0.5L 4.29492,9.33694L 0.5,5.87573L 0.5,8.38379L 5.83331,13.2482L 11.1666,8.38379L 11.1666,5.87576L 7.37183,9.33691L 7.37183,0.5L 4.29492,0.5 Z M 11.1667,16.5L 0.500061,16.5L 0.500061,14.3396L 11.1667,14.3396L 11.1667,16.5 Z " Fill="#FF000000" StrokeLineJoin="Round" />
                            </Button>
                        </StackPanel>
                        <ListBox Grid.ColumnSpan="2" Grid.Row="1" IsEnabled="{Binding ElementName=chkbox, Path=IsChecked, Mode=TwoWay}" ItemsSource="{Binding Processings}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <RadioButton GroupName="{Binding GroupName}" IsChecked="{Binding Path=isSelected, Mode=TwoWay}" Margin="1,0,10,0">
                                        <StackPanel Orientation="Horizontal">
                                            <Image Height="16" Margin="1" Source="{Binding SmallIcon}" Stretch="Uniform" Width="16" />
                                            <TextBlock Text="{Binding Name}" />
                                        </StackPanel>
                                    </RadioButton>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </CheckBox>
            </Border>
            <DataTemplate.Triggers>
                <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="border">
                    <BeginStoryboard Storyboard="{StaticResource MouseLeaveStoryboard}" Name="MouseLeaveStoryboard_BeginStoryboard" />
                </EventTrigger>
                <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="border">
                    <BeginStoryboard Storyboard="{StaticResource MouseEnterStoryboard}" />
                </EventTrigger>
                <Trigger Property="ToggleButton.IsChecked" SourceName="chkbox" Value="False">
                    <Setter Property="Border.Background" TargetName="border" Value="LightGray" />
                </Trigger>
            </DataTemplate.Triggers>
        </DataTemplate>
      

    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="126*" />
            <ColumnDefinition Width="492*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <Border BorderThickness="1" Margin="6" BorderBrush="{StaticResource SeparatorBorderBrush}" Grid.ColumnSpan="2">
            <TabControl x:Name="tabOption" Margin="1,0,0,0" Style="{DynamicResource InnerBackstageTabControlStyle}" SelectedIndex="0" >
                
                <TabItem Header="常规"  DataContext="{Binding CurrentSettings}" >
                    <ScrollViewer  Margin="10" VerticalScrollBarVisibility="Auto" >
                        <StackPanel>
                            <Label    Content="常规设置" Style="{StaticResource OptionLabelStyle}"  />

                            <StackPanel Margin="10" >
                                <CheckBox Margin="3" IsChecked="{Binding isBackupSaveDocument,Mode=TwoWay}" Content="在保存文档时备份原文件" ToolTip="如果开启此选项，在保存文档时将会备份原有内容。（默认开启）" />
                                <CheckBox Margin="3" IsChecked="{Binding isUseAdvancedDestinationEncodingList,Mode=TwoWay}" Content="使用高级输出编码" ToolTip="如果开启此选项，在保存文档时可以使用更多编码。（默认禁用）"  />
                               
                            </StackPanel>
                        </StackPanel>
                    </ScrollViewer>
                </TabItem>
                <TabItem Header="编码设置"  >
                    <Grid Margin="10" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"   Content="字符编码设置" Style="{StaticResource OptionLabelStyle}"  />
                        <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" >
                            <Run>设置使用的字符编码：</Run>
                            <LineBreak />
                            <Span>
                                <Run>注：显示</Run>
                                <Bold Foreground="Red" >红色</Bold>
                                <Run>字的编码是默认编码，无法更改。</Run>
                            </Span>
                        </TextBlock>

                        <ListBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="1" x:Name="lstEncodings" ItemsSource="{Binding EncodingList}"
                                 HorizontalContentAlignment="Stretch"
                                 ItemTemplate="{StaticResource EncodingItemTemplate}">

                        </ListBox>

                       
                    </Grid>
                </TabItem>

                <TabItem Header="插件">
                    <Grid Margin="10" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <Label Grid.Row="0"   Content="插件设置" Style="{StaticResource OptionLabelStyle}"  />
                        <TextBlock Grid.Row="1" Text="启用或禁用插件" />

                        <ListBox Grid.Row="2" x:Name="lstPlugins" Margin="3" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                  ItemsSource="{Binding PluginProviders}" ItemTemplate="{StaticResource PluginProviderTemplate}"></ListBox>
                    </Grid>
                </TabItem>


                <TabItem Header="转换设置">
                    <ScrollViewer  Margin="10" VerticalScrollBarVisibility="Auto" >
                        <StackPanel>
                            <Label   Content="转换设置" Style="{StaticResource OptionLabelStyle}"  />

                            <StackPanel Margin="10"  DataContext="{Binding CurrentSettings}" >
                                <CheckBox Margin="3" IsChecked="{Binding isSkipUnicodeConversion,Mode=TwoWay}"
                                          Content="跳过对Unicode 编码的转换" 
                                          ToolTip="如果开启此选项，在转换文档时跳过Unicode编码的文档。（默认开启）"  />
                             

                            </StackPanel>


                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                              
                                <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"   Content="使用插件" Style="{StaticResource OptionLabelStyle}"  />
                                <CheckBox x:Name="chkAutoUsePostProcessings" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content ="转换完成后使用以下插件：" IsChecked="{Binding isAutoUsePostProcessings,Mode=TwoWay }"  DataContext="{Binding CurrentSettings}" />

                                <ListBox Grid.Row="2"    Grid.Column="0" Grid.ColumnSpan="1" Height="240"
                                         HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                         IsEnabled="{Binding ElementName=chkAutoUsePostProcessings, Path=IsChecked}"
                                         ItemsSource="{Binding PluginPostProcessings}" ItemTemplate="{StaticResource UsePostProcessingItemTemplate}"></ListBox>

                              
                            </Grid>
                        </StackPanel>
                    </ScrollViewer>
                </TabItem>

              

                <TabItem Header="批处理设置"  DataContext="{Binding CurrentSettings}">
                    <ScrollViewer  Margin="10" VerticalScrollBarVisibility="Auto" >
                        <StackPanel>
                            <Label   Content="批处理设置" Style="{StaticResource OptionLabelStyle}"  />
                            <StackPanel Margin="10" >
                                <CheckBox Margin="3" IsChecked="{Binding isBatchConvertAfterAutoClose,Mode=TwoWay}" Content="转换完成后自动保存并关闭" ToolTip="如果开启此选项，在执行完批量转换后，会自动关闭转换的文档。（默认禁用）" />
                                
                            </StackPanel>
                        </StackPanel>
                    </ScrollViewer>
                </TabItem>

            </TabControl>
        </Border>

        <Button Grid.Row="1" Grid.Column="0" x:Name="btnReset" Content="重置设置" IsDefault="True" Margin="0"   Width="100" Command="Commands:OptionCommands.ResetCommand"  />

        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal"  HorizontalAlignment="Right" Margin="0,3,10,3" >

            <Button x:Name="btnOK" Content="确定" IsDefault="True" Margin="10,0,10,0"   Width="100" Command="Commands:OptionCommands.OKCommand"  />
            <Button x:Name="btnCancel" Content="取消" IsCancel="True"   Margin="10,0,10,0"   Width="100"  Command="Commands:OptionCommands.CancelCommand"/>
        </StackPanel>

    </Grid>
</Window>
